﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

namespace DLC.Module.DataTable.ArchiveBytes
{
    public static partial class DataTableBytesExtension
    {
        [BinaryReaderHelper(typeof(Vector2))]
        public static object ReadVector2(BinaryReader reader)
        {
            Vector2 value = new Vector2();
            value.x = reader.ReadSingle();
            value.y = reader.ReadSingle();
            return value;
        }


        [BinaryReaderHelper(typeof(Vector2[]))]
        public static object ReadVector2Array(BinaryReader reader)
        {
            int length = reader.ReadInt32();
            Vector2[] values = new Vector2[length];
            for (int i = 0; i < values.Length; i++)
            {
                values[i].x = reader.ReadSingle();
                values[i].y = reader.ReadSingle();
            }
            return values;
        }


        [BinaryReaderHelper(typeof(Vector2Int))]
        public static object ReadVector2Int(BinaryReader reader)
        {
            Vector2Int value = new Vector2Int();
            value.x = reader.ReadInt32();
            value.y = reader.ReadInt32();
            return value;
        }


        [BinaryReaderHelper(typeof(Vector2Int[]))]
        public static object ReadVector2IntArray(BinaryReader reader)
        {
            int length = reader.ReadInt32();
            Vector2Int[] values = new Vector2Int[length];
            for (int i = 0; i < values.Length; i++)
            {
                values[i].x = reader.ReadInt32();
                values[i].y = reader.ReadInt32();
            }
            return values;
        }


        [BinaryReaderHelper(typeof(Vector3))]
        public static object ReadVector3(BinaryReader reader)
        {
            Vector3 value = new Vector3();
            value.x = reader.ReadSingle();
            value.y = reader.ReadSingle();
            value.z = reader.ReadSingle();
            return value;
        }


        [BinaryReaderHelper(typeof(Vector3[]))]
        public static object ReadVector3Array(BinaryReader reader)
        {
            int length = reader.ReadInt32();
            Vector3[] values = new Vector3[length];
            for (int i = 0; i < values.Length; i++)
            {
                values[i].x = reader.ReadSingle();
                values[i].y = reader.ReadSingle();
                values[i].z = reader.ReadSingle();
            }
            return values;
        }


        [BinaryReaderHelper(typeof(Vector3Int))]
        public static object ReadVector3Int(BinaryReader reader)
        {
            Vector3Int value = new Vector3Int();
            value.x = reader.ReadInt32();
            value.y = reader.ReadInt32();
            value.z = reader.ReadInt32();
            return value;
        }


        [BinaryReaderHelper(typeof(Vector3Int[]))]
        public static object ReadVector3IntArray(BinaryReader reader)
        {
            int length = reader.ReadInt32();
            Vector3Int[] values = new Vector3Int[length];
            for (int i = 0; i < values.Length; i++)
            {
                values[i].x = reader.ReadInt32();
                values[i].y = reader.ReadInt32();
                values[i].z = reader.ReadInt32();
            }
            return values;
        }


        [BinaryReaderHelper(typeof(Vector4))]
        public static object ReadVector4(BinaryReader reader)
        {
            Vector4 value = new Vector4();
            value.x = reader.ReadSingle();
            value.y = reader.ReadSingle();
            value.z = reader.ReadSingle();
            value.w = reader.ReadSingle();
            return value;
        }


        [BinaryReaderHelper(typeof(Vector4[]))]
        public static object ReadVector4Array(BinaryReader reader)
        {
            int length = reader.ReadInt32();
            Vector4[] values = new Vector4[length];
            for (int i = 0; i < values.Length; i++)
            {
                values[i].x = reader.ReadSingle();
                values[i].y = reader.ReadSingle();
                values[i].z = reader.ReadSingle();
                values[i].w = reader.ReadSingle();
            }
            return values;
        }
    }
}